package com.efounder.news.http;

import com.efounder.constant.EnvironmentVariable;
import com.efounder.frame.language.MultiLanguageUtil;
import com.pansoft.xmlparse.OptionParser;

import java.util.Map;

/**
 * 新闻接口的Api
 * sunlp on 2017/11/2
 */

public class Api {

    //新闻列表
//    public static final String host = "http://211.87.224.140:8181/NewsService/";

    //    Map<String, String> newsService = OptionParser.getInstance()
//            .getElementById("newsServiceUrl");
//     String host = newsService.get("url");
    public String host;
    public String loadNews;
    public String newsDetail;

    public String getHost() {

        host = EnvironmentVariable.getProperty("newsUrl", "");
        if (!"".equals(host)) {
            return host;
        }

        Map<String, String> newsService = OptionParser.getInstance()
                .getElementById("newsServiceUrl");
        if (null == newsService || newsService.isEmpty()) {
//            host="http://211.87.224.140:8181/NewsService/";
            host = "http://news.openserver.cn/NewsService/";
        } else {
            host = newsService.get("url");
        }

        return host;
    }

    /**
     * 获取语言类型，是否是国际版,返回类型，作为调用接口的siteType参数
     * @return 国际版，返回en_US 国内版，返回zh，中文新闻
     */
    public String getNewsLocale() {
//        if (EnvSupportManager.isSupportGooglePlayUpgrade()) {
//            国际版，返回en_US
//            返回的是英文新闻
        //根据语言切换
            return isChineseNews() ? "zh" : "en_US";
//        } else {
//            //国内版，返回zh，中文新闻
//            return "zh";
//        }
    }

    /**
     * 是否国内新闻
     */
    public boolean isChineseNews() {
        String language = MultiLanguageUtil.getInstance().getSetLanguageLocale().getLanguage();
        return ("zh").equals(language);
    }

    public String getLoadNews() {
        String ho = getHost();
        loadNews = ho + "loadNews";
        return loadNews;
    }

    public String getNewsDetail() {
        String ho = getHost();
        newsDetail = ho + "news/";
        return newsDetail;
    }

    /**
     * v2接口打开后会有标题栏 在星际通讯中打开
     * @return
     */
    public String getNewsv2Detail() {
        String ho = getHost();
        newsDetail = ho + "newsv2/";
        return newsDetail;
    }
    public static String getGetAvator() {
        return getAvator;
    }

//    public static final String loadNews = host + "loadNews";
//
//    public static final String newsDetail = host + "news/";

    public static final String getAvator = "http://im.solarsource.cn:9692/IMServer/user/getAvatarData?userId=";
}
